@extends('layouts.admin')
@section('content')

<!--Side menu and right menu -->

<!-- main content -->
<section class="content home">
    <div class="container-fluid">
        <div class="block-header">
            <h2>内容管理</h2>
            <ol class="breadcrumb">
                <li><a href="/admin">首页</a></li>
                <li><a href="/admin/article">内容管理</a></li>
                <li><a href="/admin/article">文章管理</a></li>
                <li class="active">新建文章</li>
            </ol>
        </div>

        <div class="row clearfix">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                <div class="card">
                    <div class="header">
                        <h2> 新建文章 </h2>
                        <ul class="header-dropdown m-r--5">
                            <a href="{{ url()->previous() }}" title="返回上一页"> <i
                                    class="material-icons">arrow_back</i>
                            </a>
                            </li>
                        </ul>
                    </div>
                    <div class="body">
                        <form method="POST" action="">
                            {{ csrf_field() }}
                            <label for="article_title">标题</label>
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" id="article_title" class="form-control" name="article_title" maxlength="150" value="{{request()->input('article_title')}}">
                                </div>
                                @if ($errors->has('article_title'))
                                <label id="name-error" class="error" for="article_title">{{ $errors->first('article_title') }}</label>
                                @endif
                            </div>
                            <label for="article_title">文章分类</label>
                             <div class="row clearfix"></div>
                            <div class="col-sm-3">
                                <select class="form-control" name="article_class_id" >
                                    @foreach($cate as $key=>$val)
                                    <option value="{{$val['class_id']}}">{{$val['class_name']}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="row clearfix"></div>
                            <label class="control-label" for="article_abstract">文章摘要</label>
                            <div class="form-group ">
                                <div class="form-line">
                                   <textarea id="article_abstract" class="form-control" name="article_abstract" rows="3" aria-required="true"> {{request()->input('article_abstract')}}</textarea>
                                </div>
                            </div>
                            <label class="control-label" for="article_keyword">文章关键字</label>
                            <div class="form-group ">
                                <div class="form-line">
                                    <input type="text" id="article_keyword" class="form-control" name="article_keyword" value="{{request()->input('article_keyword')}}" maxlength="150">
                                </div>
                            </div>
                            <label for="exampleInputFile">封面</label>
                            <div class="form-group">
                                <div class="col-md-3">
                                    <span class="thumbnail article_image_div"></span>
                                </div>
                                <div class="col-md-3">

                                </div>
                                <div class="col-md-6">

                                    <div style="position: relative; position: relative;margin-top: -59px;">
                                        <a class="btn btn-raised btn-success waves-effect" href="javascript:void(0);">
                                            <i class="material-icons">touch_app</i>
                                        </a>
                                        <input type="file" name="tempfile"
                                               style="opacity: 0;width:100%;height: 30px;" id="InputFile">
                                        <div class="form-group" >
                                            <span class="label label-info">支持png,jpg,gif等格式</span> <span
                                                class="label label-warning">文件名不能为汉字</span>
                                        </div>
                                    </div>
                                </div>
                                <input type="hidden" id="article_image" class="article_image" name="article_image" value="{{request()->input('article_image')}}">
                            </div>
                            <div class="row clearfix"></div>
                            <label class="control-label" for="content">内容</label>
                            <div class="form-group">
                                <textarea id="article_content" class="form-control" name="article_content">{{request()->input('article_content')}}</textarea>

                                @if ($errors->has('article_content'))
                                <label id="name-error" class="error" for="article_content">{{ $errors->first('article_content') }}</label>
                                @endif
                            </div>
                      
                            
                            <label  for="article_click">点击量</label>
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" id="article_click" class="form-control" value="1" name="article_click">
                                </div>
                            </div>
                            <label  for="article_sort">文章排序</label>
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" id="article_sort" class="form-control" value="1" name="article_sort">
                                </div>
                            </div>
                            <label  for="article_publish_time">发布时间</label>
                            <div class="form-group">
                                <div class="form-line">
                                    <input type="text" id="article_publish_time" class="form-control" value="{{date("Y-m-d H:i:s")}}" name="article_publish_time">
                                </div>
                            </div>

                            <div class="hidden-print">
                                <div class="pull-right">

                                    <button type="reset" class="btn  btn-raised bg-grey waves-effect">重置内容</button>
                                    <button type="submit" class="btn  btn-raised btn-success waves-effect">创建文章
                                    </button>

                                </div>
                            </div>

                        </form>
                    </div>
                </div>
            </div>


        </div>
    </div>
</section>

@endsection
@push('header-css')
<link href="{{ asset('assets/plugins/redactor2/redactor.css') }}" rel="stylesheet">
<link href="{{ asset('assets/plugins/bootstrap-select/css/bootstrap-select.css') }}" rel="stylesheet" />
@endpush

@push('scripts')
<script type="text/javascript" charset="utf-8" src="{{ asset('assets/plugins/redactor2/redactor.min.js')}}"></script>
<script type="application/javascript">
    $(function ($) {

    $('#article_content').redactor({
    plugins:['source','table','fontcolor','fontsize','inlinestyle','fullscreen'],
    buttons: ['format', 'bold', 'italic', 'deleted', 'lists', 'image', 'file', 'link', 'horizontalrule' ,'horizontalrule', 'underline', 'ol', 'ul', 'indent', 'outdent'], // +
    minHeight: "300px",
    maxHeight: "500px",
    imageUploadParam:'imageFile',
    fileUploadParam:'imageFile',
    imageUpload: '{{Route('admin.upload.images')}}',
    placeholder: '请输入内容.....',
    X_CSRF_TOKEN:'{{csrf_token()}}',
    });


    $('#InputFile').change(function () {
    var File_Data = new FormData();
    File_Data.append('imageFile', $("#InputFile")[0].files[0]);
    File_Data.append('resize', 'true');
    $.ajax({
    data: File_Data,
    type: "POST",
    url: "{{Route('admin.upload.images')}}",
    cache: false,
    contentType: false,
    processData: false,
    dataType: "json",
    beforeSend: function (xhr) {
    xhr.setRequestHeader("X-CSRF-TOKEN", "{{csrf_token()}}");
    },
    success: function (ret) {
    if (ret.error == true) {
    alert(ret.message);
    } else {
    $('.article_image').val(ret.url);
    $('#InputFile').val('');
    $('.article_image_div').html("<img src='" + ret.url + "' data-id='" + ret.id + "'   />");
    }
    console.log(ret);
    }
    });
    });
    });
</script>
@endpush